#include <egos_types.h>
#include <egos_logging.h>
#include <i_task.h>
#include <i_scheduler.h>

#define EGOS_MAX_NUM_TASKS		100

static EGOS_TaskControlBlock allTasks[EGOS_MAX_NUM_TASKS];
static uint32 numEgosActiveTasks = 0;

void EgosInitAllTasks()
{
	uint32 i;
	for(i = 0; i < EGOS_MAX_NUM_TASKS; i++)
	{
		allTasks[i]._taskFunc 		= NULL;
		allTasks[i].id				= i;
		allTasks[i].activePriority 	= 0;
		allTasks[i].priority 		= 0;
		allTasks[i].state			= EGOS_TASK_STATE_INACTIVE;
	}
}

EgosTaskId EgosCreateTask(void (*_taskFunc)(void*), uint32 priority)
{
	// TODO:
	// Do we need it to be thread safe?? or task creation is a startup operation and we will support only static threads??

	if(numEgosActiveTasks == EGOS_MAX_NUM_TASKS)
	{
		PRINT("Can't create task, system reached maximum number of tasks");
		return INVALID_EGOS_TASK_ID;
	}

	allTasks[numEgosActiveTasks]._taskFunc = _threadFunc;
	allTasks[numEgosActiveTasks].priority = priority;
	allTasks[numEgosActiveTasks].activePriority = priority;

	// increment number of tasks
	numEgosActiveTasks++;

	return numEgosActiveTasks - 1;
}

EgosTaskId EgosGetCurrentTaskID()
{
	return __egosSchedulerGetCurrentTask();
}

EgosTaskHandle EgosGetTaskHandle(EgosTaskId)
{

}
